﻿using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.ComponentModel.Design;

namespace SampleControl.Design {
    // This designer class simply adds an action to smart tag enabling user
    // to show/hide border easily.
    public class MyControlDesigner : ControlDesigner {
        private DesignerActionListCollection dalc;

        public override DesignerActionListCollection ActionLists {
            get {
                if (dalc == null) {
                    dalc = new DesignerActionListCollection();
                    dalc.AddRange(base.ActionLists);
                    UserControl ctrl = Component as UserControl;
                    if (ctrl != null) {
                        dalc.Add(new ShowBorderActionList(ctrl));
                    }
                }
                return dalc;
            }
        }

        internal class ShowBorderActionList : DesignerActionList {
            private UserControl myCtrl;

            public ShowBorderActionList(UserControl control) : base(control) {
                myCtrl = control;
            }

            public bool ShowBorder {
                get { return myCtrl.BorderStyle != BorderStyle.None; }
                set { myCtrl.BorderStyle = value ? BorderStyle.FixedSingle : BorderStyle.None; }
            }
        }
    }
}